package ch.ethz.fcl.metrobuzz.data.accessibility.activity;

import java.io.File;
import java.util.List;

import ch.ethz.fcl.metrobuzz.MBProperty;
import ch.ethz.fcl.metrobuzz.data.MBData;

public class MBActivity {
	private MBData data = null;

	private String workFile = "res/Singapore/poi/work";
	private List<PointOfInterest> work = null;

	private String sportsFile = "res/Singapore/poi/sports";
	private List<PointOfInterest> sports = null;

	private String childCareFile = "res/Singapore/poi/child_care";
	private List<PointOfInterest> childCare = null;

	private String elderCareFile = "res/Singapore/poi/elder_care";
	private List<PointOfInterest> elderCare = null;

	private String librariesFile = "res/Singapore/poi/libraries";
	private List<PointOfInterest> libraries = null;
	
	private String residentsFile = "res/Singapore/poi/Residents_Committees";
	private List<PointOfInterest> residents = null;

	public MBActivity(MBData data) {
		this.data = data;
	}

	public void init() {
		if (new File(workFile).exists())
			work = POIReaderWritter.readFromWrittenFile(data, workFile);
		else {
			work = POIReaderWritter.readFromCSVFile(data, MBProperty.WORK_FILE);
			POIReaderWritter.saveToFile(data, work, workFile);
		}

		if (new File(sportsFile).exists()) {
			sports = POIReaderWritter.readFromWrittenFile(data, sportsFile);
		} else {
			sports = POIReaderWritter.readFromShapeFile(data,
					MBProperty.POI_FILE_FOLDER, "Sports_Centres");
			POIReaderWritter.saveToFile(data, sports, sportsFile);
		}

		if (new File(childCareFile).exists()) {
			childCare = POIReaderWritter.readFromWrittenFile(data,
					childCareFile);
		} else {
			childCare = POIReaderWritter.readFromShapeFile(data,
					MBProperty.POI_FILE_FOLDER, "Child_Care_Services");
			POIReaderWritter.saveToFile(data, childCare, childCareFile);
		}

		if (new File(elderCareFile).exists()) {
			elderCare = POIReaderWritter.readFromWrittenFile(data,
					elderCareFile);
		} else {
			elderCare = POIReaderWritter.readFromShapeFile(data,
					MBProperty.POI_FILE_FOLDER, "Eldercare");
			POIReaderWritter.saveToFile(data, elderCare, elderCareFile);
		}

		if (new File(librariesFile).exists()) {
			libraries = POIReaderWritter.readFromWrittenFile(data,
					librariesFile);
		} else {
			libraries = POIReaderWritter.readFromShapeFile(data,
					MBProperty.POI_FILE_FOLDER, "Libraries_25");
			POIReaderWritter.saveToFile(data, libraries, librariesFile);
		}
		
		if (new File(residentsFile).exists()) {
			residents = POIReaderWritter.readFromWrittenFile(data,
					residentsFile);
		} else {
			residents = POIReaderWritter.readFromShapeFile(data,
					MBProperty.POI_FILE_FOLDER, "Residents_Committees");
			POIReaderWritter.saveToFile(data, residents, residentsFile);
		}
	}

	public List<PointOfInterest> getSports() {
		return sports;
	}

	public List<PointOfInterest> getWork() {
		return work;
	}

	public List<PointOfInterest> getChildCare() {
		return childCare;
	}

	public List<PointOfInterest> getElderCare() {
		return elderCare;
	}

	public List<PointOfInterest> getLibraries() {
		return libraries;
	}
	
	public List<PointOfInterest> getResidents() {
		return residents;
	}
}
